package com.liang.exam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liang.exam.entity.ExamStudent;
import com.liang.exam.entity.Teacher;
import com.liang.exam.mapper.TeacherMapper;
import com.liang.exam.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.liang.exam.entity.Exam;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {

    @Autowired
    private TeacherMapper teacherMapper;

    @Override
    public Teacher findByAccount(String account) {
        return teacherMapper.findByAccount(account);
    }

    @Override
    public void createExam(Exam exam) {
        teacherMapper.createExam(exam);
    }

    @Override
    public Exam getExamInfo(Integer examId) {
        return teacherMapper.getExamInfo(examId);
    }

    @Override
    public void updateExam(Exam exam) {
        teacherMapper.updateExam(exam);
    }

    @Override
    public PageInfo<Exam> selectAll(Integer pageNum, Integer pageSize, Integer teacherId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exam = teacherMapper.selectAll(teacherId);
        PageInfo<Exam> pageInfo = new PageInfo<>(exam);
        return pageInfo;
    }

    @Override
    public void deleteExam(Integer examId) {
        teacherMapper.deleteExam(examId);
    }

    @Override
    public PageInfo<Exam> searchExam(Integer pageNum, Integer pageSize, Exam exam) {
        PageHelper.startPage(pageNum,pageSize);
        List<Exam> exam1 = teacherMapper.searchExam(exam);
        PageInfo<Exam> pageInfo = new PageInfo<>(exam1);
        return pageInfo;
    }

    @Override
    public void updateExamStatus(Integer examId) {
        teacherMapper.updateExamStatus(examId);
    }

    @Override
    public Teacher findById(int teacherId) {
        return teacherMapper.findById(teacherId);
    }

    @Override
    public void updatePassword(String password, int teacherId) {
        teacherMapper.updatePassword(password,teacherId);
    }

    @Override
    public PageInfo<ExamStudent> selectExamStudent(Integer pageNum, Integer pageSize, Integer id) {
        PageHelper.startPage(pageNum,pageSize);
        List<ExamStudent> exam = teacherMapper.selectExamStudent(id);
        PageInfo<ExamStudent> pageInfo = new PageInfo<>(exam);
        return pageInfo;
    }

    @Override
    public void addStudentExam(ExamStudent examStudent) {
        teacherMapper.addStudentExam(examStudent);
    }

    @Override
    public void addStudentExamList(List<ExamStudent> studentList, String eId) {
        teacherMapper.addStudentExamList(studentList, eId);
    }

    @Override
    public PageInfo<ExamStudent> findStudentExam(ExamStudent examStudent, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<ExamStudent> student = teacherMapper.findStudentExam(examStudent);
        PageInfo<ExamStudent> pageInfo = new PageInfo<>(student);
        return pageInfo;
    }

    @Override
    public void deleteStudent(Integer id) {
        teacherMapper.deleteStudent(id);
    }


}
